(function(jQuery) {
	/*
	 * 货品查询放大镜JS插件
	 */

	var gridColMenu_Detail = null;

	$.MagnifierHPSUtils = {
		/**
		 * 页面初始化函数
		 */
		init : function() {
			var name = encodeURI($('#condition').val());
			var gAccountNo = encodeURI($('#magnifierHPPageNew_i_gAccountNo').val());
			// 创建列表DataGrid
			$('#magnifierHPSPage_hp_new')
					.datagrid(
							{
								url : 'magnifier/getMagnifierHPList.do?catch='
										+ new Date() 
										+ '&name='
										+ name
										+ '&gAccountNo='
										+ gAccountNo,
								method : 'get',
								title : $.i18n.prop("js.magnifier.title.hp"),
								iconCls : 'icon-large-smartart',
								pagination : true,
								rownumbers : true,
								striped : true,
								pageSize : 10,
								pageList : [10],
								columns : [ [ {
									field : 'hp',
									checkbox : true
								},{
									field : 'id',
									title : $.i18n.prop("js.magnifier.datagrid.xh"),
									hidden : true,
									width : 0
								}, {
									field : 'code',
									title : $.i18n.prop("js.magnifier.datagrid.hpbm"),
									width : 200,
									align : 'left'
								}, {
									field : 'name',
									title : $.i18n.prop("js.magnifier.datagrid.hpmc"),
									width : 233,
									align : 'left'
								}, {
									field : 'price',
									title : $.i18n.prop("js.magnifier.datagrid.dj"),
									hidden : true,
									width : 0
								} ] ],

								onLoadError: function(){
									$.LmisUtils.opLoadError();
								}
							});
		},

		/**
		 * 查询
		 */
		search : function() {
			var name = encodeURI($('#condition').val());
			var gAccountNo = encodeURI($('#magnifierHPPageNew_i_gAccountNo').val());
			$('#magnifierHPSPage_hp_new')
					.datagrid(
							{
								url : 'magnifier/getMagnifierHPList.do?catch='
										+ new Date() 
										+ '&name='
										+ name
										+ '&gAccountNo='
										+ gAccountNo
							});
		},
		/**
		 * 确定
		 */
		ok : function() {
			var selectedHPs = $('#magnifierHPSPage_hp_new').datagrid(
					'getSelections');
			var id = "";
			var code = "";
			var name = "";
			var index = 0;
			for (index = 0; index < selectedHPs.length; index++) {
				if (index == 0) {
					id = id + selectedHPs[index].id;
					code = code + selectedHPs[index].code;
					name = name + selectedHPs[index].name;
				} else {
					id = id + "," + selectedHPs[index].id;
					code = code + "," + selectedHPs[index].code;
					name = name + "," + selectedHPs[index].name;
				}
			}
			//向父页面赋值
			if ($('#magnifierHPPageNew_id').val() != null && $('#magnifierHPPageNew_id').val().length > 0) {
				$("#" + $('#magnifierHPPageNew_id').val()).val(id);
			}
			if ($('#magnifierHPPageNew_code').val() != null && $('#magnifierHPPageNew_code').val().length > 0) {
				$("#" + $('#magnifierHPPageNew_code').val()).val(code);
			}
			if ($('#magnifierHPPageNew_name').val() != null && $('#magnifierHPPageNew_name').val().length > 0) {
				$("#" + $('#magnifierHPPageNew_name').val(),
						window.parent.document).searchbox(
						'setValue', name);
			}
			//关闭放大镜窗口
			$("#magnifier_window").window('close');
		}
	};
})(jQuery);
$.MagnifierHPSUtils.init();
